<%--
  Created by IntelliJ IDEA.
  User: admin
  Date: 2022/5/8
  Time: 0:09
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>地点管理</title>
    <!-- 引入bootstrap -->
    <link rel="stylesheet" type="text/css" href="/css/bootstrap.min.css">
    <!-- 引入JQuery  bootstrap.js-->
    <script src="/js/jquery-3.2.1.min.js"></script>
    <script src="/js/bootstrap.min.js"></script>
    <script src="/js/jquery.easyui.min.js"></script>
</head>
<body>
<!-- 顶栏 -->
<jsp:include page="top.jsp"></jsp:include>
<div class="container"><ul>
    <a id="add1" class="btn btn-info" href="javascript:" role="button">增加子节点</a>
    <a id="add2" class="btn btn-info" href="javascript:" role="button">增加兄弟节点</a>
    <a id="delete" class="btn btn-info" href="javascript:" role="button">删除当前</a>
</ul></div>
<div class="container" id="content">
    <div class="row">
<div class="col-md-3">
    <div class="panel panel-default">
        <div class="panel-heading">
            <div class="row">

                <ul id="messageInfoAddTree"  class="easyui-tree" data-options="lines:true" style="height:94%">
                </ul>
            </div>
        </div>
    </div>
</div>
        <div id="content2" class="col-md-6" data-example-id="bordered-table">
            <form class="form-horizontal" role="form"  id="from1" method="post">
            <h4>地点信息</h4>
            <table class="table table-bordered">
                <thead>
                <tr>
                    <th>标题</th>
                    <th>输入</th>
                </tr>
                </thead>
                <tbody>
                <tr>
                    <th scope="row">地点编号</th>
                    <td><input type="text" name="placeNumber" id="place"></td>
                </tr>
                <tr>
                    <th scope="row">地点名称</th>
                    <td><input type="text" name="placeName" id="placen"></td>
                </tr>
                </tbody>
            </table>
                <div class="col-sm-offset-2 col-sm-10">
                    <button type="button" class="btn btn-default btn-info" id="save">保存</button>
                    <button type="button" class="btn btn-default btn-info" id="exit"><a href="/admin/showPlan">取消</a></button>
                </div>
            </form>
        </div>
        <div id="content3">

        </div>

    </div>
</div>
</body>
<script type="text/javascript">
    $('#messageInfoAddTree').tree({


            method:"get",
            url: "/plan/list",
            loadFilter: function(data){
                return data.data;

            },
        onLoadSuccess: function(){
            var txt1="<a href='javascript:'></a>";
            $(".tree-node").wrap(txt1)
        },
        onClick: function(node,data){

            $("#place").empty()
            $("#placen").empty()

            $("#place").attr('value',node.placeNumber)

            $("#placen").attr('value',node.placeName)

            $(function () {
                $("#save").click(function () {
                    var content1=$("#place").val()
                    var option1=$('#placen').val();

                    var searchMap = {
                        "id" : node.id,
                        "text": option1,
                        "placeNumber" :content1,
                        "placeName":option1
                    };
                    $.ajax({
                        url: '/plan/',
                        type: 'put',
                        dataType:'json',
                        data: JSON.stringify(searchMap),
                        contentType: "application/json",
                        success: function () {
                            alert("保存成功")
                            window.location.href="/plan/editPlace";

                        },
                        error: function () {
                            alert("保存失败")
                        }
                    })
                })
                $("#delete").click(function () {
                    if(confirm("确定要删除吗？")){
                    $.ajax({
                        url: '/plan/'+node.id,
                        type: 'delete',
                        success: function () {
                            alert("删除成功")
                            window.location.href="/plan/editPlace";
                        },
                        error: function () {
                            alert("删除失败")
                        }
                    })}
                })
                $("#add1").click(function () {
                    $("#place").removeAttr("value")
                    $("#placen").removeAttr("value")
                    $('#save').unbind();
                    $("#place").attr("placeholder","请输入编号")
                    $("#placen").attr("placeholder","请输入地点")
                    $("#save").click(function (){
                    var content1=$("#place").val()
                    var option1=$('#placen').val();

                    var searchMap = {
                        "id" : node.id,
                        "parentId":node.parentId,
                        "text": option1,
                        "type":node.type,
                        "accidentId":node.accidentId,
                        "placeNumber" :content1,
                        "placeName":option1
                    };
                    $.ajax({
                        url: '/plan/children/'+node.id,
                        type: 'post',
                        dataType:'json',
                        data: JSON.stringify(searchMap),
                        contentType: "application/json",
                        success: function () {
                            alert("保存成功")
                            window.location.href="/plan/editPlace";

                        },
                        error: function () {
                            alert("保存失败")
                        }
                    })})
                })
                $("#add2").click(function () {
                    $("#place").removeAttr("value")
                    $("#placen").removeAttr("value")
                    $('#save').unbind();
                    $("#place").attr("placeholder","请输入编号")
                    $("#placen").attr("placeholder","请输入地点")
                    $("#save").click(function (){
                    var content1=$("#place").val()
                    var option1=$('#placen').val();
                    var searchMap = {
                        "id" : node.id,
                        "parentId":node.parentId,
                        "text": option1,
                        "type":node.type,
                        "accidentId":node.accidentId,
                        "placeNumber" :content1,
                        "placeName":option1
                    };
                    $.ajax({
                        url: '/plan/brother/'+node.id,
                        type: 'post',
                        dataType:'json',
                        data: JSON.stringify(searchMap),
                        contentType: "application/json",
                        success: function () {
                            alert("保存成功")
                            window.location.href="/plan/editPlace";

                        },
                        error: function () {
                            alert("保存失败")
                        }
                    })})
                })
            })
        }

    });

</script>
</html>
